﻿using System;

namespace awsomeSyntezator.PipeLine.Oscilators
{
	class Pulse : Oscilator
    {
		private Random pulseRandomizer;
		private int randomIndex;
		private double sign;
        public Pulse(float _freq) : base(_freq, 0, 1)
        {
            type = 0;
			pulseRandomizer = new Random((int)DateTime.Now.Ticks);
        	randomIndex = pulseRandomizer.Next(1, (int)_freq);
        }
        public Pulse(float _freq, int strenght) : base(_freq, 0, strenght)
        {
			type = 0;
			pulseRandomizer = new Random((int)DateTime.Now.Ticks);
			randomIndex = pulseRandomizer.Next(1, (int)_freq);
        }
        public override double getSample(int n, double sample)
        {
			if (n == randomIndex)
			{
				randomIndex += pulseRandomizer.Next(1, (int)frequency);
				sign = (pulseRandomizer.NextDouble() - 0.5) * 2.0;
				return sign;
			}
        	return 0.0;
        }
    }
}
